from vec import *
from time import sleep
WIDTH = 300
HEIGHT = 400

BACK_COLOR = (60, 10, 255)
PEN_COLOR = (0, 0, 50)

rcHeight = [80,160,100,60,140,40,120]
start_pt=0
end_pt=0
rcWidth = 20
space = 10
no_move=1
i=0
j=0
p=-0.01
pspd=0.1
class MyRect:
    def __init__(self, lb_x, lb_y, h, clr):
        self.pos = Vec2(lb_x, lb_y)
        self.h = h
        self.clr = clr
        
    def Update(self):
        pass

    def Draw(self):
        rc = Rect((self.pos.x, self.pos.y - self.h), (rcWidth, self.h))
        screen.draw.filled_rect(rc, self.clr)

startX = 50
iter = startX
rcList = []
for item in rcHeight:
    r = int(item*1.133)
    g = int(item*1.133)
    b = int(item*1.313)
    rcList.append(MyRect(iter, HEIGHT / 2, item, (r, g, b)))
    iter += rcWidth
    iter += space

def swap(num):
    global p, rcList,pspd,start_pt,end_pt,no_move
    no_move=0.5
    if p < 1.0:
        p += pspd
        print(end_pt.raw_get())
    else:
        p = 1.0
        no_move=0
    rcList[num].pos.x = start_pt.x * (1 - p) + end_pt.x * p
    rcList[num+1].pos.x = start_pt.x * p + end_pt.x * (1 - p)

    
def update():
    global rcHeight,rcList,start_pt,end_pt,i,j,no_move
    if rcHeight[j] >rcHeight[j+1] :
        if no_move==1:
            start_pt=rcList[j].pos
            end_pt=rcList[j+1].pos
            swap(j)
        elif no_move==0.5:
            swap(j)
        elif no_move==0:
            if j==len(rcList)-i-1 :
                i+=1
                j=0
            else:
                j+=1
            no_move=1
    
def draw():
    screen.clear()
    screen.fill(BACK_COLOR)
    screen.draw.line((0, HEIGHT / 2), (WIDTH, HEIGHT / 2), PEN_COLOR)
    for rc in rcList:
        rc.Draw()
